#ifndef _Registers
#define _Registers
#include <iostream>
#include <cstring>
#include <cstdio>
#include "store.hpp"
#include "arithmetic.hpp"
#include "tomasulo_cpu.hpp"

void CPU::reg_run()
{
    #ifdef func
        puts("");
        puts("---reg_run---");
    #endif 
    
    CPU::R_new = CPU::R_prev;

    const CPU::CDB &t = CPU::commit_to_reg;

    if (~t.dest)
    {
        CPU::R_new.reg[t.dest] = t.val;
        if (CPU::R_new.reg_state[t.dest] == t.pos)
            CPU::R_new.reg_state[t.dest] = -1;

        CPU::R_new.reg[0] = 0;
    }

    if (CPU::commit_signal < 0)
    {
        for (int i = 0; i < 32; i++)
            CPU::R_new.reg_state[i] = -1;
        return;
    }

    std::pair<int, int> p = CPU::issue_to_reg;
    if (~p.first)
        CPU::R_new.reg_state[p.first] = p.second;

    #ifdef func
        puts("-------------");
        puts("");
    #endif 
}

#endif